package com.steven.ourcontest.information.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.gson.annotations.SerializedName
import com.steven.ourcontest.base.BaseViewModel
import com.steven.ourcontest.information.api.InfoApi
import com.steven.ourcontest.information.bean.IdentifyStatusResponse
import com.steven.ourcontest.information.bean.ManageUsersDetailsRes
import com.steven.ourcontest.information.bean.SchoolList
import com.steven.ourcontest.information.bean.UserNameResponse
import com.steven.ourcontest.information.bean.UserDetail
import com.steven.ourcontest.login.helper.LoginController
import com.steven.ourcontest.me.bean.UsersDetailsRes
import com.steven.ourcontest.net.EmptyResponse
import com.steven.ourcontest.utils.Identity
import com.steven.ourcontest.utils.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class AdminManageViewModel : BaseViewModel() {
    private val _usersList = MutableLiveData<ManageUsersDetailsRes?>()
    val usersList: LiveData<ManageUsersDetailsRes?>
        get() = _usersList

    private val _updateRes = MutableLiveData<EmptyResponse?>()
    val updateRes: LiveData<EmptyResponse?>
        get() = _updateRes

    private var querying = false
    fun queryToBeConfirm() {
        if (querying) {
            return
        }
        disposed += InfoApi.instance.queryToBeConfirm()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                querying = false
                _usersList.value = it.result
            }, {
                querying = false
                it.printStackTrace()
            })
    }

    private var updating = false
    fun updateIdentifyStatus(normalUser: Long, canPass: Boolean) {
        if (updating) {
            return
        }
        updating = true
        disposed += InfoApi.instance.updateIdentifyStatus(normalUser, canPass)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                updating = false
                _updateRes.value = it.result
            }, {
                updating = false
                it.printStackTrace()
            })
    }
}